package cn.datawin.bms.modules.customer.service.impl;

import cn.datawin.bms.customer.entity.CstmCorporateEntity;
import cn.datawin.bms.modules.customer.mapper.CstmCorporateMapper;
import cn.datawin.bms.modules.customer.service.CstmCorporateService;
import cn.datawin.common.core.util.RedisUtils;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

import static cn.datawin.constant.RedisPattern.CSTM_CORPORATE_START;

/**
 * 下游客户公司
 *
 * @author datawin-sms
 * @date 2025-06-16 21:00:17
 */
@Service
public class CstmCorporateServiceImpl extends ServiceImpl<CstmCorporateMapper, CstmCorporateEntity> implements CstmCorporateService {
    @Override
    public CstmCorporateEntity newCstmCorporate() {
		if(!RedisUtils.hasKey(CSTM_CORPORATE_START)){
			RedisUtils.incr(CSTM_CORPORATE_START, 100000L);
		}
		long account = RedisUtils.incr(CSTM_CORPORATE_START,1L);
		CstmCorporateEntity cstmCorporateEntity = new CstmCorporateEntity();
		cstmCorporateEntity.setCode(account+"");
		String key = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 8);
		cstmCorporateEntity.setPwd(key);
		cstmCorporateEntity.setStatus(1);

		return cstmCorporateEntity;
    }

    @Override
    public List<CstmCorporateEntity> getByIds(List<Long> corporateIdList) {
		if(CollUtil.isEmpty(corporateIdList)){
			return CollUtil.newArrayList();
		}
		return this.baseMapper.selectBatchIds(corporateIdList);
    }
}
